package com.hj.learn.demo1;

public class Teststop implements Runnable {

   private boolean flag = true;
    @Override
    public void run() {
        int i = 0;
        while (flag){
            System.out.println("run------Thread"+i++);
        }
    }
    //设置一个停止的方法
    public void stop(){
        this.flag = false;
    }

    public static void main(String[] args) {
        Teststop teststop =  new Teststop();
        new Thread(teststop).start();

        for (int i = 0; i < 1000; i++) {
            System.out.println("main"+i);
            if(i==900){
                teststop.stop();
                System.out.println("线程停止");
            }
        }
    }
}
